package com.big.oss.controller;


import com.big.common.result.Result;
import com.big.oss.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/api/oss/file")
public class FileApiController {

    @Autowired
    private FileService fileService;

    //上传文件到阿里云oss
    @PostMapping("fileUpload")
    public Result fileUpload(MultipartFile file) {
        //获取上传文件
        String url = fileService.upload(file);
        return Result.ok(url);
    }

    //上传文件到阿里云oss
    @PostMapping("fileUploads")
    public Result fileUploads(@RequestBody  MultipartFile[] files) {
        //获取上传文件
        List<String> uploads = fileService.uploads(files);
        return Result.ok(uploads);
    }


    //删除文件
    @DeleteMapping("/fileDelete/{bucketCode}")
    public Result fileUploads(@PathVariable Integer bucketCode,@RequestParam("objectUrl")  String objectUrl) {
        boolean flag = fileService.deleteFile(bucketCode,objectUrl);
        return Result.ok(flag);
    }

    //上传文件到阿里云oss
    @PostMapping("/picturesFileUpload")
    public Result picturesFileUpload(MultipartFile file) {
        //获取上传文件
        String url = fileService.uploadPictures(file);
        return Result.ok(url);
    }


}
